﻿using System;
using System.Linq;
using Hjt212Parser;
using log4net;
using TcpServer.Facade;
using TcpServer.Orm;

namespace TcpServer.DataProcessor
{
    class Platform9012Processor : IProcessor
    {
        private readonly ILog log = LogManager.GetLogger(typeof(Platform9012Processor));

        public void Persist()
        {
            throw new NotImplementedException();
        }

        public void Persist(DustEntities context, SocketClientInfo content)
        {
            if (string.IsNullOrWhiteSpace(content.MN)) return;
            try
            {
                log.Info(content.ReceivedMsg);
                //有效字符串
                if (Parser.IsLengthRight(content.ReceivedMsg))
                {
                    //获取QN
                    var qn = Parser.GetStringByKey("QN", content.ReceivedMsg);
                    using (var ctx=new DustEntities())
                    {
                       
                        var items= ctx.SetFactorThresholds.Where(t => t.QN != null && t.QN.Contains(qn));
                        foreach (var item in items)
                        {
                            item.执行结果="同步成功";
                            
                        }
                        ctx.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error( ex);
               
            }
        }
        public void Persist(DataCommunicationEntities context, SocketClientInfo content)
        {
            throw new NotImplementedException();
        }
    }
}
